#include "cilib.h"

void ciRgb2yuv(PIXEL *rc,PIXEL *yuv)
{
    char r,g,b;
    r=rc->r;
    g=rc->g;
    b=rc->b;
    
    ((YUVPIXEL*)yuv)->y = 0.299 * r + 0.587 * g + 0.114 * b;
    ((YUVPIXEL*)yuv)->u = -0.147 * r -0.289 * g + 0.436 * b;
    ((YUVPIXEL*)yuv)->v = 0.615 * r -0.515 * g -0.100 * b;
}

void ciYuv2rgb(PIXEL *yuv,PIXEL* rgb)
{
    char y,u,v;
    y=((YUVPIXEL*)yuv)->y;
    u=((YUVPIXEL*)yuv)->u;
    v=((YUVPIXEL*)yuv)->v;
    
    
    rgb->r = y + 1.402*v;
    rgb->g = y - 0.334*u - 0.714*v;
    rgb->b = y - 1.772*u;
}
    
